import 'package:flutter/material.dart';
import 'package:schedule_self_client/utils/time_util.dart';

class DeadlineWidget extends StatefulWidget {
  final void Function(DateTime? dateTime) dateSelectCallback;
  final DateTime? deadline;

  const DeadlineWidget(
      {super.key, required this.dateSelectCallback, this.deadline});

  @override
  State<DeadlineWidget> createState() => _DeadlineWidgetState();
}

class _DeadlineWidgetState extends State<DeadlineWidget> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () async {
        if (context.mounted) {
          DateTime? dateTime = await showDatePicker(
              context: context,
              firstDate: DateTime.utc(1970),
              lastDate: DateTime.utc(9999));
          if (dateTime != null) {
            widget.dateSelectCallback(dateTime);
          }
        }
      },
      child: Row(
        children: [
          const Icon(Icons.calendar_month),
          const SizedBox(width: 8),
          Text(
              TimeUtil.formatTimeForHuman(widget.deadline, context, '请选择截止日期')),
        ],
      ),
    );
  }
}
